<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 橙子柚子。
  Date: 2018/3/20
  Time: 20:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>小脚本测试</title>
</head>
<body>
<%
    //注册数据驱动
    Class.forName("com.mysql.jdbc.Driver");
    //获取数据库连接
    Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/1613580007_2?characterEncoding=utf8", "root", "123456789");
    //创建statement
    Statement stmt=conn.createStatement();
    //执行查询
    ResultSet rs=stmt.executeQuery("SELECT * FROM news_inf");
    %>
     <table bgcolor="#9999dd" border="1" width="300px">
    <%
    //遍历循环
    while(rs.next())
    {
        %>
         <tr>
             <!--输出结果集-->
             <td><%=rs.getString(1)%></td>
             <td><%=rs.getString(2)%></td>
         </tr>
         <%
    }
%>
 </table>
</body>
</html>
